package com.jiejie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jiejie.entity.Cast;
import com.jiejie.entity.MovieAndCast;
import com.jiejie.mapper.CastMapper;
import com.jiejie.mapper.MovieAndCastMapper;
import com.jiejie.service.IMovieAndCastService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 辰广
 * @since 2022-10-05
 */
@Service
public class MovieAndCastServiceImpl extends ServiceImpl<MovieAndCastMapper, MovieAndCast> implements IMovieAndCastService {
@Resource
private MovieAndCastMapper mcMapper;
@Resource
private CastMapper castMapper;
    @Override
//    演员
    public Map<MovieAndCast, Cast> getCastYYByMovidId(Integer movieId) {
        QueryWrapper<MovieAndCast> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("movie_id",movieId);
        queryWrapper.ne("movie_and_cast_role","导演");
        List<MovieAndCast> movieAndCast=mcMapper.selectList(queryWrapper);
        Map<MovieAndCast, Cast> movieAndCastCastMap=new HashMap<>();

        for(int i=0;i<movieAndCast.size();i++){
            MovieAndCast movieAndCast1= movieAndCast.get(i);
            Cast cast=castMapper.selectById(movieAndCast1.getCastId());
            movieAndCastCastMap.put(movieAndCast1,cast);
        }
        return movieAndCastCastMap;
    }
    //    导演
    @Override
    public Map<MovieAndCast, Cast> getCastDYByMovidId(Integer movieId) {
        QueryWrapper<MovieAndCast> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("movie_id",movieId);
        queryWrapper.eq("movie_and_cast_role","导演");
        List<MovieAndCast> movieAndCast=mcMapper.selectList(queryWrapper);
        Map<MovieAndCast, Cast> movieAndCastCastMap=new HashMap<>();

        for(int i=0;i<movieAndCast.size();i++){
            MovieAndCast movieAndCast1= movieAndCast.get(i);
            Cast cast=castMapper.selectById(movieAndCast1.getCastId());
            movieAndCastCastMap.put(movieAndCast1,cast);
        }
        return movieAndCastCastMap;
    }


}
